/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function docfragToString(docfrag){
    var div=document.createElement("div");
    div.appendChild(docfrag);
    return div.innerHTML;
}
function getXmlHttpObj(){
    var xml;
    if (window.XMLHttpRequest){
        xml=new XMLHttpRequest();
    } else {
        xml=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xml;
}
function createTextInputFromDiv(divElement){
    var text=divElement.innerHTML;
    var input=document.createElement("input");
    input.setAttribute("type", "text");
    input.setAttribute("value", text);
    if(divElement.className){
        input.className=divElement.className;
    }
    var parent=divElement.parentNode;
    parent.removeChild(divElement);
    parent.appendChild(input);
    return input;
}
function getParentByTagName(obj, tag)
{
    var obj_parent = obj.parentNode;
    if (!obj_parent) return false;
    if (obj_parent.tagName.toLowerCase() == tag) return obj_parent;
    else return getParentByTagName(obj_parent, tag);
}

function getParentByClassName(obj, classname)
{
    var obj_parent = obj.parentNode;
    if (!obj_parent) return false;
    if (obj_parent.className.toLowerCase() == classname) return obj_parent;
    else return getParentByClassName(obj_parent, classname);
}
function transformXmlAndXsl(xmlDoc,xslDoc,parameters)
{
    var result;
    var xsltProcessor;
    // code for Mozilla, Firefox, Opera, etc.
    if (document.implementation && document.implementation.createDocument&&window.XSLTProcessor) {
        xsltProcessor=new XSLTProcessor();
        xsltProcessor.importStylesheet(xslDoc);
        if (parameters != null) {
            for (var i=0;i<parameters.length;i++) {
                var para = parameters[i];
                xsltProcessor.setParameter(null,para.name,para.value);
            }
        }
        var ownerDocument = document.implementation.createDocument("", "", null);
        result = xsltProcessor.transformToFragment(xmlDoc, ownerDocument);
    } else
    // code for IE
    if (window.ActiveXObject) {
        var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate");
        var xslLoader=new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
        xslLoader.async = false;
        xslLoader.load(xslDoc);
        xslTemplate.stylesheet=xslLoader;
        var xslProc=xslTemplate.createProcessor();
        xslProc.input=xmlDoc;
        if (parameters != null) {
            for (var j=0;j<parameters.length;j++) {
                var paraObj = parameters[j];
                xslProc.addParameter(paraObj.name,paraObj.value);
                
            }
        }
        xslProc.transform();
        var outString=xslProc.output;
        result=stringToFragment(outString);
    }
    return result;
}

function getNumber(xmlDoc,elementPath){
    if (xmlDoc.evaluate) {
        var nodes = xmlDoc.evaluate(elementPath, xmlDoc, null, XPathResult.NUMBER_TYPE, null);
        return nodes.numberValue;
    }
    else{
        return xmlDoc.selectSingleNode(elementPath);
    }
}
function stringToFragment(html) {
    var doc = window.document;
    var container = doc.createElement("div");
    container.innerHTML = html;
    var frag = doc.createDocumentFragment(), n;
    while ((n = container.firstChild)) {
        frag.appendChild(n);
    }
    return frag;
};
function loadSourceDoc(type,name)
{
    var xhttp;
    if (window.XMLHttpRequest) {
        xhttp=new XMLHttpRequest();
    } else {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var data="action=FindResource&type="+type+"&name="+name;
    xhttp.open("GET",contextPath+"/XmlController?"+data,false);
    try {
        xhttp.responseType = "msxml-document";
    } catch (e) { }
    xhttp.send();
    return xhttp.responseXML;
}
function convertToUnsign(input){
    var signedChars     = "àảãáạăằẳẵắặâầẩẫấậđèẻẽéẹêềểễếệìỉĩíịòỏõóọôồổỗốộơờởỡớợùủũúụưừửữứựỳỷỹýỵÀẢÃÁẠĂẰẲẴẮẶÂẦẨẪẤẬĐÈẺẼÉẸÊỀỂỄẾỆÌỈĨÍỊÒỎÕÓỌÔỒỔỖỐỘƠỜỞỠỚỢÙỦŨÚỤƯỪỬỮỨỰỲỶỸÝỴ";
    var unsignedChars   = "aaaaaaaaaaaaaaaaadeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYY";
    var pattern = new RegExp("[" + signedChars + "]", "g");
    var result = input.replace(pattern, function (m, key, value) {
        return unsignedChars.charAt(signedChars.indexOf(m));
    });
    return result;
}
function getSingleNode(xmlDoc, elementPath) {
    if (xmlDoc.evaluate) {
        var nodes = xmlDoc.evaluate(elementPath, xmlDoc, null, XPathResult.ANY_TYPE, null);
        return nodes.iterateNext();
    }
    else{
        return xmlDoc.selectSingleNode(elementPath);
    }
}
function XMLToString(oXML) {
    if (window.ActiveXObject) {
        return oXML.xml;
    } else {
        return (new XMLSerializer()).serializeToString(oXML);
    }
}